package com.ruoyi.web.controller.cat;

import com.ruoyi.cat.domain.CatActivityTable;
import com.ruoyi.cat.domain.CatArticletaskTable;
import com.ruoyi.cat.domain.CatTradedetailTable;
import com.ruoyi.cat.domain.VO.ArticTaskTableVO;
import com.ruoyi.cat.service.ICatApplycashoutTableService;
import com.ruoyi.cat.service.ICatArticletaskTableService;
import com.ruoyi.cat.service.ICatTradedetailTableService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.OrderUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "管理端-文章审核")
@RestController
@RequestMapping("/system/articleReview")
public class ArticleReviewController extends BaseController {

    @Autowired
    private ICatArticletaskTableService catArticletaskTableService;

    @Autowired
    private ICatTradedetailTableService catTradedetailTableService;

    @ApiOperation("获取文章审核列表")
    @GetMapping("/list")
    public TableDataInfo list(CatArticletaskTable catArticletaskTable)
    {
        catArticletaskTable.setInvitationSource("1");
        catArticletaskTable.setArticleExamine("1");
        startPage();
        List<CatArticletaskTable> list = catArticletaskTableService.selectCatArticletaskData(catArticletaskTable);
        return getDataTable(list);
    }

    @ApiOperation("审核接口")
    @PostMapping("/examine")
    public AjaxResult add(@RequestBody ArticTaskTableVO articTaskTableVO)
    {
        CatArticletaskTable catActivityTable = new CatArticletaskTable();
        catActivityTable.setArticleExamine(articTaskTableVO.getArticleExamine());
        catActivityTable.setId(articTaskTableVO.getId());
        CatTradedetailTable catTradedetailTable = new CatTradedetailTable();
        String orderNo = OrderUtil.makeOrderNo();
        catTradedetailTable.setOrderNo(orderNo);
        catTradedetailTable.setActivityId(articTaskTableVO.getId());
        catTradedetailTable.setStatus("1");
        catTradedetailTable.setTradeType("1");
        catTradedetailTable.setType("1");
        catTradedetailTableService.insertCatTradedetailTable(catTradedetailTable);
        return toAjax(catArticletaskTableService.updateCatArticletaskTable(catActivityTable));
    }

    @ApiOperation("修改信息")
    @PutMapping
    public AjaxResult edit(@RequestBody CatArticletaskTable catArticletaskTable)
    {
        return toAjax(catArticletaskTableService.updateCatArticletaskTable(catArticletaskTable));
    }

    @ApiOperation("获取详情")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(catArticletaskTableService.selectCatArticletaskContentTableById(id));
    }







}
